package com.umeox.quranplayer.db.dao

import androidx.room.*
import com.umeox.quranplayer.db.model.ChallengeRecord

/**
 * Created by Rambo 2021/11/19
 * Describe:
 */
@Dao
interface ChallengeRecordDao {

    @Query("SELECT * FROM challenge_record WHERE isUpload = 0 AND isComplete = 0")
    fun loadAllNotUploadRecords(): MutableList<ChallengeRecord>?

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun save(challengeRecord: ChallengeRecord): Long

    @Update(onConflict = OnConflictStrategy.REPLACE)
    fun update(challengeRecord: ChallengeRecord): Int

    @Query("SELECT * FROM challenge_record WHERE todayMillis = :todayMillis AND quranLearnId = :quranLearnId AND chapterIndex = :chapterIndex")
    fun queryCurrentChallengeRecord(todayMillis: Int,quranLearnId: Int, chapterIndex: Int): ChallengeRecord?

    @Query("SELECT duration FROM challenge_record WHERE todayMillis = :todayMillis AND quranLearnId = :quranLearnId AND chapterIndex = :chapterIndex")
    fun getCurrentCompleteDuration(todayMillis: Int, quranLearnId: Int, chapterIndex: Int): Int

    @Query("DELETE FROM challenge_record")
    fun deleteAll(): Int
}